package cc.marcio.systems.seven.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "t_action", uniqueConstraints = { @UniqueConstraint(columnNames = { "id" }) })
@SequenceGenerator(name = "seq_action", sequenceName = "seq_action")
public class Action implements Serializable {

	private static final long serialVersionUID = -5605981471841614491L;

	public static final Integer ACTION_ATTACK = 1;
	
	public static final Integer ACTION_DEFENSE = 2;
	
	public static final Integer ACTION_FALLBACK = 3;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_action")
	@Column( unique = true, insertable = false, updatable = false )
	private Long id;
	
	@ManyToOne
	@JoinColumns({@JoinColumn(name="round_id"),@JoinColumn(name="user_id")})
	private Planet planet; 
	
	private Integer sector;
	
	private Integer galaxia;
	
	private Integer slot;
	
	private String name;
	
	private Integer ships;
	
	private Integer tickArrive;
	
	private Integer tickAction;
	
	private Integer squad;
	
	private Integer action;
	
	private Boolean isActive;
	
	@Column( nullable = true, unique = false, insertable = true, updatable = true )
	private String parser;

	public Action() {
		this.isActive = true;
	}
	
	public Action(Planet planet) {
		this();
		this.planet = planet;
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Planet getPlanet() {
		return planet;
	}

	public void setPlanet(Planet planet) {
		this.planet = planet;
	}

	public Integer getSector() {
		return sector;
	}

	public void setSector(Integer sector) {
		this.sector = sector;
	}

	public Integer getGalaxia() {
		return galaxia;
	}

	public void setGalaxia(Integer galaxia) {
		this.galaxia = galaxia;
	}

	public Integer getSlot() {
		return slot;
	}

	public void setSlot(Integer slot) {
		this.slot = slot;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getShips() {
		return ships;
	}

	public void setShips(Integer ships) {
		this.ships = ships;
	}

	public Integer getTickArrive() {
		return tickArrive;
	}

	public void setTickArrive(Integer tickArrive) {
		this.tickArrive = tickArrive;
	}

	public Integer getTickAction() {
		return tickAction;
	}

	public void setTickAction(Integer tickAction) {
		this.tickAction = tickAction;
	}

	public Integer getSquad() {
		return squad;
	}

	public void setSquad(Integer squad) {
		this.squad = squad;
	}

	public Integer getAction() {
		return action;
	}

	public void setAction(Integer action) {
		this.action = action;
	}

	public String getParser() {
		return parser;
	}

	public void setParser(String parser) {
		this.parser = parser;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public static Integer getActionAttack() {
		return ACTION_ATTACK;
	}

	public static Integer getActionDefense() {
		return ACTION_DEFENSE;
	}

	public static Integer getActionFallback() {
		return ACTION_FALLBACK;
	}

	public Boolean getIsActive() {
		return isActive;
	}

	public void setIsActive(Boolean isActive) {
		this.isActive = isActive;
	}
	
	public String getSummary() {
		StringBuilder newMessage = new StringBuilder();
		
		if( this.getAction().equals(Action.ACTION_ATTACK ) ) {
			newMessage.append("Ataque - ");
			newMessage.append(this.getSector() + ":" + this.getGalaxia() + ":" + this.getSlot());
			newMessage.append(" - TAD " + this.getTickArrive());
			newMessage.append(" - " + this.getShips() + " naves");
		} else if( this.getAction().equals(Action.ACTION_DEFENSE ) ) {
			newMessage.append("Defesa - ");
			newMessage.append(this.getSector() + ":" + this.getGalaxia() + ":" + this.getSlot());
			newMessage.append(" - TAD " + this.getTickArrive());
			newMessage.append(" - " + this.getShips() + " naves");
		} else if( this.getAction().equals(Action.ACTION_FALLBACK ) ) {
			newMessage.append("Recuo - ");
			newMessage.append(this.getSector() + ":" + this.getGalaxia() + ":" + this.getSlot());
		}
		return newMessage.toString();
	}
}
